package org.example.distributedlock.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.example.distributedlock.pojo.StockDb;

public interface StockMapper extends BaseMapper<StockDb> {

    @Update("update STOCK_DB set COUNT = COUNT - #{count} where PRODUCT_CODE = #{productCode} and COUNT >= #{count}")
    void deductStock(@Param("productCode") String productCode, @Param("count") int count);

    @Select("select * from STOCK_DB where PRODUCT_CODE = #{productCode} for update")
    StockDb selectStock(@Param("productCode") String productCode);
}
